package com.hw.backapi.controller;

import com.hw.backapi.service.IOssService;
import com.hw.backapi.service.impl.DiagTaskServiceImpl;
import com.hw.backapi.service.impl.OssServiceImpl;
import com.hw.common.annotation.MyLogAdmin;
import com.hw.common.contants.UrlContants;
import com.hw.model.common.BaseResult;
import com.hw.model.dto.overview.DetailedQueryDTO;
import com.hw.model.dto.overview.PatientDetailedQueryDTO;
import org.apache.ibatis.annotations.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.TimeUnit;

/**
 * @author lipeng
 * @description 患者控制器
 * @date 2023/3/8 8:35
 */
@RestController
public class PatientController {
    @Autowired
    IOssService ossServiceImpl;

    /**
     * @descrition 患者列表
     * @author lipeng
     * @date 2023/3/8
     * @param patientDetailedQueryDTO
     * @return com.hw.model.common.BaseResult
     */
    @PostMapping(UrlContants.PATIENT_LIST)
    public BaseResult patientList(
            @RequestBody PatientDetailedQueryDTO patientDetailedQueryDTO
    ){
        return BaseResult.ok(ossServiceImpl.patientDetailed(patientDetailedQueryDTO));
    }

    /**
     * @descrition 测试一下时长
     * @author lipeng
     * @date 2023/6/27
     * @param
     * @return com.hw.model.common.BaseResult
     */
    @GetMapping(UrlContants.PATIENT_DEMO)
    public BaseResult patiendDemo(){
        try{
            TimeUnit.SECONDS.sleep(80);
        } catch (InterruptedException e) {
//            e.printStackTrace();
        }

        return BaseResult.ok("80秒后成功响应demo");
    }

    /**
     * @descrition 导出患者明细
     * @author lipeng
     * @date 2023/3/8
     * @param patientDetailedQueryDTO
     * @return void
     */
    @MyLogAdmin(label = "导出患者明细")
    @GetMapping(UrlContants.PATIENT_DETAIL_EXPORT)
    public void exportDetailed(
            PatientDetailedQueryDTO patientDetailedQueryDTO
    ){
        ossServiceImpl.exportDetailed(patientDetailedQueryDTO);
    }

    /**
     * @descrition  批量导出患者文件
     * @author lipeng
     * @date 2023/3/8
     * @param patientDetailedQueryDTO
     * @param request
     * @param response
     * @return void
     */
    @MyLogAdmin(label = "批量导出患者文件")
    @PostMapping(UrlContants.PATIENT_BATCH_DOWNLOAD)
    public void batchDownload(
            @RequestBody PatientDetailedQueryDTO patientDetailedQueryDTO, HttpServletRequest request, HttpServletResponse response
    ){
        ossServiceImpl.batchDownload(patientDetailedQueryDTO,request,response);
    }
}

